package com.ehualu.check.es;


import com.ehualu.check.utils.CheckThread;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;

import org.elasticsearch.common.xcontent.XContentFactory;

import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.InetAddress;
import java.util.concurrent.ExecutionException;

public class EsUpdatetest {

    private static final Logger LOG = LoggerFactory.getLogger(EsUpdatetest.class);

    public void updateIndex()throws IOException, ExecutionException, InterruptedException   {


            Settings settings = Settings.builder().put("cluster.name", "test")
//                .put("client.transport.sniff", false)
                    .build();
            TransportClient client = new PreBuiltTransportClient(settings)
                    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("172.16.101.63"), 9300));
            UpdateRequest updateRequest = new UpdateRequest();

            updateRequest.index("data_center_platform_csh")
                    .type("data_ext")
                    .id("2beb9158cd3a436f8acedea7bd9b9f44")
//                    .id("2beb")
                    .doc(XContentFactory.jsonBuilder()
                            .startObject()
                            .field("urlType", "ftptestchange")
                            .field("extName", "testchagne")

                            .endObject()
                    );
            LOG.info("开始修改");
            UpdateResponse response1 = client.update(updateRequest).get();
            System.out.println(response1.status());
            client.close();


        //执行修改



        //查询修改状态，返回ok表示成功

        System.out.println("**************************");

    }


    public static void main(String[] args) {


        EsUpdatetest esUpdatetest=new EsUpdatetest();
        try {
            esUpdatetest.updateIndex();
        } catch (Exception e) {
            LOG.info("修改失败");
            e.printStackTrace();
        }

    }


}
